package com.dangs.autotest.service;

import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.os.IBinder;
import android.provider.Settings;
import com.dangs.autotest.ui.FloatView;


public class FloatService extends Service {

    private final String TAG = "FloatService";
    private FloatView floatView;

    @Override
    public void onCreate() {
        super.onCreate();
    }

    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        getConfigAndShow();
        return super.onStartCommand(intent, flags, startId);
    }


    void getConfigAndShow() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            if (Settings.canDrawOverlays(this)) {
                FloatView.Config config = FloatView.Config.getConfigFromLocal(this);
                if (floatView!= null && floatView.isShown()) {
                    floatView.hide();
                    floatView = null;
                }
                floatView = new FloatView(getApplicationContext());
                floatView.show(config);
            }
        }
    }


}
